package org.cuijq.thinking.in.spring.bean.definition;

import org.cuijq.thinking.in.spring.ioc.domain.User;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.GenericBeanDefinition;

/**
 *  BeanDefinitionCreationDemo 构建
 */
public class BeanDefinitionCreationDemo {
    public static void main(String[] args) {
        //1.BeanDefinition build
        //User user =new User();
        BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(User.class);
        beanDefinitionBuilder.addPropertyValue("name","cuijq");
        beanDefinitionBuilder.addPropertyValue("age",34);
        BeanDefinition beanDefinition = beanDefinitionBuilder.getBeanDefinition();
        //2.
        GenericBeanDefinition genericBeanDefinition = new GenericBeanDefinition();
        genericBeanDefinition.setBeanClass(User.class);
        MutablePropertyValues propertyValues= new MutablePropertyValues();
//        propertyValues.add("age",22);
//        propertyValues.add("name","name");

//        propertyValues.addPropertyValue("age",22);
//        propertyValues.addPropertyValue("name","cuijq");

        propertyValues.add("age",22).
                add("name","name");
        genericBeanDefinition.setPropertyValues(propertyValues);
    }


}
